function plotIterPSNR(psnr0_bar, ssim0_bar, netnameList, psnrsList, ssimsList, BestModelList, ModelItersList, bPlotStartingPSNR, PSNR_SSIM_Figures)

if ~exist('PSNR_SSIM_Figures', 'var'), PSNR_SSIM_Figures = [figure figure]; end

if ~iscell(netnameList), netnameList = {netnameList}; end
if ~iscell(psnrsList), psnrsList = {psnrsList}; end
if ~iscell(ssimsList), ssimsList = {ssimsList}; end
if ~iscell(BestModelList), BestModelList = {BestModelList}; end

%%
psnrBarList = cellfun(@mean, psnrsList, 'UniformOutput', false);
ssimBarList = cellfun(@mean, ssimsList, 'UniformOutput', false);

%%
% for i = 1 : length(psnrsList)
%     psnr_bar = sort(psnrBarList{i});  ssim_bar = sort(ssimBarList{i});
%     
%     fprintf('\n\nThe results of PSNR/SSIM for "%s" are as follows:\n', netnameList{i});
%     fprintf('Starting\tMax\t\tMin\t\tMean\n');
%     fprintf('%.3f/%.4f\t%.3f/%.4f\t%.3f/%.4f\t%.3f/%.4f.\n\n', ...
%     psnr0_bar, ssim0_bar, psnr_bar(end), ssim_bar(end), psnr_bar(1), ssim_bar(1), mean(psnr_bar), mean(ssim_bar));
%     
%     if ~isempty(BestModelList)
%         fprintf('Best Caffemodel with Max PSNR is "%s".\n', BestModelList{i}.PSNR);
%         fprintf('Best Caffemodel with Max SSIM is "%s".\n', BestModelList{i}.SSIM);
%     end
% end

% [psnrMax, psnrMaxIdx] = getMaxPSNR(psnrBarList);
% [ssimMax, ssimMaxIdx] = getMaxPSNR(ssimBarList);
% 
% for i = 1 : length(psnrsList)
%     % psnr_best_model = parseBestModel(BestModelList{i}.PSNR);
%     % ssim_best_model = parseBestModel(BestModelList{i}.SSIM);
%     
%     fprintf('"%s":\t%.3f/%.4f\t%g/%g\n', netnameList{i}, psnrMax(i), ssimMax(i), psnrMaxIdx(i), ssimMaxIdx(i));
% end
% fprintf('\n');

%%
figure(PSNR_SSIM_Figures(1)); plotQualityCurve('PSNR', psnr0_bar, netnameList, psnrBarList, ModelItersList, bPlotStartingPSNR);
figure(PSNR_SSIM_Figures(2)); plotQualityCurve('SSIM', ssim0_bar, netnameList, ssimBarList, ModelItersList, bPlotStartingPSNR);

% function [psnrMax, psnrMaxIdx] = getMaxPSNR(psnrBarList)
% [psnrMax, psnrMaxIdx] = cellfun(@max, psnrBarList, 'UniformOutput', false);
% psnrMax = cell2num(psnrMax);
% psnrMaxIdx = cell2num(psnrMaxIdx);

function best_model = parseBestModel(best_model)
[~, best_model] = fileparts(best_model);
kk = strfind(best_model, '_');
best_model = best_model(kk(end)+1 : end);

function plotQualityCurve(Measure, psnr0_bar, netnameList, psnrBarList, ModelIters, bPlotStartingPSNR)

Len = max(cellfun(@length, psnrBarList));

hold on;
if bPlotStartingPSNR, plot(psnr0_bar(ones(1, Len))); end
cellfun(@plot, psnrBarList);

xlabel('Iteration'); ylabel(Measure);
if bPlotStartingPSNR
    h = legend('Starting', netnameList{:});
else
    h = legend(netnameList{:});
end
set(h, 'Interpreter', 'none', 'location', 'best'); % 'northwest');
axis tight
box on

%%
ylim = get(gca, 'ylim');
[vals, idx] = cellfun(@max, psnrBarList, 'UniformOutput', false);
for i = 1 : length(vals)
    plot(idx{i}([1 1]), [ylim(1) vals{i}], 'LineWidth', .5, 'LineStyle', '--', 'Color',[1 0 0])
end
